import request from '../utils/request';
import { stringify } from 'qs';
import { baseServerUrl } from '../utils/Constant';

export async function splitPage(params) {
  return request(`${baseServerUrl}/tms/tms-order/split-page?${stringify(params)}`, {
    method: 'GET',
  });
}

export async function splitSave(params) {
  return request(`${baseServerUrl}/tms/tms-order/split`, {
    method: 'POST',
    body: params,
  });
}

export async function splitDel(params) {
  return request(`${baseServerUrl}/tms/tms-order/split/${params.id}`, {
    method: 'DELETE',
  });
}

export async function splitDelLn(params) {
  return request(`${baseServerUrl}/tms/tms-order/split-ln/${params.id}`, {
    method: 'DELETE',
  });
}

export async function dispatchPage(params) {
  return request(`${baseServerUrl}/tms/tms-cost/dispatch-page?${stringify(params)}`, {
    method: 'GET',
  });
}

export async function auditPage(params) {
  return request(`${baseServerUrl}/tms/tms-order/audit-page?${stringify(params)}`, {
    method: 'GET',
  });
}

export async function costInsertOrUpdate(params) {
  const { id } = params;
  let method = 'PUT';
  if (id === 0) {
    method = 'POST';
    delete params['id'];
  }
  return request(`${baseServerUrl}/tms/tms-cost`, {
    method: method,
    body: {
      ...params,
    },
  });
}

export async function costOrders(params) {
  return request(`${baseServerUrl}/tms/tms-cost/cost-orders`, {
    method: 'POST',
    body: params,
  });
}

export async function costApply(params) {
  return request(`${baseServerUrl}/tms/tms-cost/cost-apply`, {
    method: 'POST',
    body: params,
  });
}

export async function costDel(params) {
  return request(`${baseServerUrl}/tms/tms-cost`, {
    method: 'DELETE',
    body: params,
  });
}

export async function auditCostPage(params) {
  return request(`${baseServerUrl}/tms/tms-cost/audit-page?${stringify(params)}`, {
    method: 'GET',
  });
}

export async function auditCost(params) {
  return request(`${baseServerUrl}/tms/tms-cost/audit-cost`, {
    method: 'POST',
    body: params,
  });
}

export async function finishCost(params) {
  return request(`${baseServerUrl}/tms/tms-cost/finish`, {
    method: 'POST',
    body: params,
  });
}

export async function rollbackSplit(params) {
  return request(`${baseServerUrl}/tms/tms-order/rollback-split`, {
    method: 'POST',
    body: params,
  });
}

export async function splitReject(params) {
  return request(`${baseServerUrl}/tms/tms-order/split-reject`, {
    method: 'POST',
    body: params,
  });
}

export async function applyPay(params) {
  return request(`${baseServerUrl}/tms/tms-cost/applyPay`, {
    method: 'POST',
    body: params,
  });
}

export async function urgentCost(params) {
  return request(`${baseServerUrl}/tms/tms-cost/urgentPay`, {
    method: 'POST',
    body: params,
  });
}

export async function rejectCost(params) {
  return request(`${baseServerUrl}/tms/tms-cost/reject`, {
    method: 'POST',
    body: params,
  })
}

export async function invoiceReject(params) {
  return request(`${baseServerUrl}/tms/tms-order/invoice-reject`, {
    method: 'POST',
    body: params,
  })
}

export async function feeSum(params) {
  return request(`${baseServerUrl}/tms/tms-cost/sumFee?${stringify(params)}`, {
    method: 'GET',
  });
}

export async function updateAccount(params) {
  return request(`${baseServerUrl}/tms/tms-cost/updateAccount`, {
    method: 'POST',
    body: params,
  })
}

